#include <iostream>
#include <math.h>
using namespace std;
//点结构体
struct Point
{
    int x; //横坐标
    int y; //纵坐标
};
typedef struct Point point;
void mainMenu();                              //菜单函数
void getPoints(point *start, point *end);     //获取圆两个坐标
void drawCircle(point *start, point *end);    //画圆函数
void drawRectangle(point *start, point *end); //画矩形函数
void printPoints(int x, int y);               //打印(x,y)形式的点
int main()
{
    point Pstart, Pend;
    while (1)
    {
        int flag;
        mainMenu();
        cout << "Please enter a shape: ";
        cin >> flag;
        if (flag == 0)
        {
            cout << "Good Bye!" << endl;
            break;
        }
        switch (flag)
        {
        case 1:
            getPoints(&Pstart, &Pend);
            drawCircle(&Pstart, &Pend);
            break;
        case 2:
            getPoints(&Pstart, &Pend);
            drawRectangle(&Pstart, &Pend);
            break;
        default:
            cout << "Please enter the legitimate number again!" << endl;
            break;
        }
    }
    return 0;
}

void mainMenu()
{
    cout << "*************************" << endl;
    cout << "\t1.  Circle" << endl;
    cout << "\t2.  Rectangle" << endl;
    cout << "\t0.  Exit" << endl;
    cout << "*************************" << endl;
}
void printPoints(int x, int y)
{
    cout << "(" << x << "," << y << ")";
}
void getPoints(point *start, point *end)
{
    int x, y;
    while (1)
    {
        cout << "Please input the start coordinates : ";
        cin >> x >> y;
        if (x < 0 || y < 0)
        {
            cout << "Please enter a positive number." << endl;
        }
        else
        {
            start->x = x;
            start->y = y;
            break;
        }
    }
    while (1)
    {
        cout << "Please input the end coordinates : ";
        cin >> x >> y;
        if (x < 0 || y < 0)
        {
            cout << "Please enter a positive number." << endl;
        }
        else
        {
            end->x = x;
            end->y = y;
            break;
        }
    }
}
void drawCircle(point *start, point *end)
{
    int sumX = start->x + end->x;
    int sumY = start->y + end->y;
    if (end->x < start->x || end->y < start->y || sumY % 2 == 1 || sumX % 2 == 1)
    {
        cout << "Not a Circle, please enter again!" << endl;
        return;
    }
    int centerX, centerY;
    float radius;
    centerX = sumX / 2;
    centerY = sumY / 2;
    radius = sqrt(pow(end->x - start->x, 2) + pow(end->y - start->y, 2)) / 2.0;
    cout << "Center of circle: ";
    printPoints(centerX, centerY);
    cout << " radius : " << radius << endl;
}
void drawRectangle(point *start, point *end)
{
    float height, width;
    height = end->y - start->y;
    width = end->x - start->x;
    cout << "Rectangle's topLeft : ";
    printPoints(start->x, start->y);
    cout << "  height : " << height << "  width : " << width << endl;
}